home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / xulrunner-1.9.0.14 / chrome / toolkit.jar / content / global / bindings / wizard.xml < prev   
Encoding:
Extensible Markup Language  |  2007-04-19  |  17.6 KB  |  508 lines

  1. <?xml version="1.0"?>
  2.  
  3. <!DOCTYPE bindings [
  4.   <!ENTITY % globalDTD SYSTEM "chrome://global/locale/global.dtd">
  5.   %globalDTD;
  6.   <!ENTITY % wizardDTD SYSTEM "chrome://global/locale/wizard.dtd">
  7.   %wizardDTD;
  8. ]>
  9.  
  10. <bindings id="wizardBindings"
  11.    xmlns="http://www.mozilla.org/xbl"
  12.    xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  13.    xmlns:xbl="http://www.mozilla.org/xbl">
  14.  
  15.   <binding id="wizard-base">
  16.     <resources>
  17.       <stylesheet src="chrome://global/skin/wizard.css"/>
  18.     </resources>
  19.   </binding>
  20.   
  21.   <binding id="wizard" extends="chrome://global/content/bindings/wizard.xml#wizard-base">
  22.     <content>
  23.       <xul:hbox class="wizard-header" chromedir="&locale.dir;" anonid="Header"/>
  24.       
  25.       <xul:deck class="wizard-page-box" flex="1" anonid="Deck">
  26.         <children includes="wizardpage"/>
  27.       </xul:deck>
  28.       <children/>
  29.       
  30.       <xul:hbox class="wizard-buttons" anonid="Buttons" xbl:inherits="pagestep,firstpage,lastpage"/>
  31.     </content>
  32.     
  33.     <implementation>
  34.       <property name="title" onget="return document.title;"
  35.                              onset="return document.title = val;"/>
  36.  
  37.       <property name="canAdvance" onget="return this._canAdvance;"
  38.                                   onset="this._nextButton.disabled = !val; return this._canAdvance = val;"/>
  39.       <property name="canRewind" onget="return this._canRewind;"
  40.                                  onset="this._backButton.disabled = !val; return this._canRewind = val;"/>
  41.  
  42.       <property name="pageStep" readonly="true" onget="return this._pageStack.length"/>
  43.  
  44.       <field name="pageCount">0</field>
  45.       
  46.       <field name="_accessMethod">null</field>
  47.       <field name="_pageStack">null</field>
  48.       <field name="_currentPage">null</field>
  49.  
  50.       <property name="wizardPages">
  51.         <getter>
  52.         <![CDATA[
  53.           var xulns = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  54.           return this.getElementsByTagNameNS(xulns, "wizardpage");
  55.         ]]>
  56.         </getter>
  57.       </property>
  58.  
  59.       <property name="currentPage" onget="return this._currentPage">
  60.         <setter>
  61.         <![CDATA[
  62.           if (!val)
  63.             return val;
  64.             
  65.           this._currentPage = val;
  66.  
  67.           // Setting this attribute allows wizard's clients to dynamically
  68.           // change the styles of each page based on purpose of the page. 
  69.           this.setAttribute("currentpageid", val.pageid);
  70.                     
  71.           if (this.onFirstPage) {
  72.             this.canRewind = false;
  73.             this.setAttribute("firstpage", "true");
  74.             this._backButton.setAttribute('hidden', 'true');
  75.           } else {
  76.             this.canRewind = true;
  77.             this.setAttribute("firstpage", "false");
  78.             this._backButton.setAttribute('hidden', 'false');
  79.           }
  80.                     
  81.           if (this.onLastPage) {
  82.             this.canAdvance = true;
  83.             this.setAttribute("lastpage", "true");
  84.           } else {
  85.             this.setAttribute("lastpage", "false");
  86.           }
  87.  
  88.           this._deck.setAttribute("selectedIndex", val.pageIndex);
  89.           this._advanceFocusToPage(val);
  90.  
  91.           this._adjustWizardHeader();
  92.           this._wizardButtons.onPageChange();
  93.  
  94.           this._fireEvent(val, "pageshow");
  95.           
  96.           return val;
  97.         ]]>
  98.         </setter>
  99.       </property>
  100.  
  101.       <property name="pageIndex"
  102.                 onget="return this._currentPage ? this._currentPage.pageIndex : -1;">
  103.         <setter>
  104.         <![CDATA[
  105.           if (val < 0 || val >= this.pageCount)
  106.             return val;
  107.  
  108.           var page = this.wizardPages[val];
  109.           this._pageStack[this._pageStack.length-1] = page;
  110.           this.currentPage = page;
  111.  
  112.           return val;
  113.         ]]>
  114.         </setter>
  115.       </property>
  116.  
  117.       <property name="onFirstPage" readonly="true"
  118.                 onget="return this._pageStack.length == 1;"/>
  119.  
  120.       <property name="onLastPage" readonly="true">
  121.         <getter><![CDATA[
  122.           var cp = this.currentPage;
  123.           return cp && ((this._accessMethod == "sequential" && cp.pageIndex == this.pageCount-1) ||
  124.                        (this._accessMethod == "random" && cp.next == ""));
  125.          ]]></getter>
  126.       </property>
  127.  
  128.       <method name="getButton">
  129.         <parameter name="aDlgType"/>
  130.         <body>
  131.         <![CDATA[
  132.           var btns = this.getElementsByAttribute("dlgtype", aDlgType);
  133.           return btns.item(0) ? btns[0] : document.getAnonymousElementByAttribute(this._wizardButtons, "dlgtype", aDlgType);
  134.         ]]>
  135.         </body>
  136.       </method>
  137.  
  138.       <field name="_canAdvance"/>
  139.       <field name="_canRewind"/>
  140.       <field name="_wizardHeader"/>
  141.       <field name="_wizardButtons"/>
  142.       <field name="_deck"/>
  143.       <field name="_backButton"/>
  144.       <field name="_nextButton"/>
  145.       <field name="_cancelButton"/>
  146.  
  147.       <!-- functions to be added as oncommand listeners to the wizard buttons -->
  148.       <field name="_backFunc">(function() { document.documentElement.rewind(); })</field>
  149.       <field name="_nextFunc">(function() { document.documentElement.advance(); })</field>
  150.       <field name="_finishFunc">(function() { document.documentElement.advance(); })</field>
  151.       <field name="_cancelFunc">(function() { document.documentElement.cancel(); })</field>
  152.       <field name="_extra1Func">(function() { document.documentElement.extra1(); })</field>
  153.       <field name="_extra2Func">(function() { document.documentElement.extra2(); })</field>
  154.  
  155.       <field name="_closeHandler">(function(event) {
  156.         if (document.documentElement.cancel())
  157.           event.preventDefault();
  158.       })</field>
  159.        
  160.       <constructor><![CDATA[
  161.         this._canAdvance = true;
  162.         this._canRewind = false;
  163.         this._hasLoaded = false;
  164.         
  165.         this._pageStack = [];
  166.         
  167.         try {
  168.           // need to create string bundle manually instead of using <xul:stringbundle/>
  169.           // see bug 63370 for details
  170.           var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"]
  171.                                 .getService(Components.interfaces.nsILocaleService);
  172.           var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"]
  173.                                       .getService(Components.interfaces.nsIStringBundleService);
  174.           var bundleURL = "chrome://global/locale/wizard.properties";
  175.           this._bundle = stringBundleService.createBundle(bundleURL);
  176.         } catch (e) {
  177.           // This fails in remote XUL, which has to provide titles for all pages
  178.           // see bug 142502
  179.         }
  180.         
  181.         // get anonymous content references
  182.         this._wizardHeader = document.getAnonymousElementByAttribute(this, "anonid", "Header");
  183.         this._wizardButtons = document.getAnonymousElementByAttribute(this, "anonid", "Buttons");
  184.         this._deck = document.getAnonymousElementByAttribute(this, "anonid", "Deck");
  185.         
  186.         this._initWizardButton("back");
  187.         this._initWizardButton("next");
  188.         this._initWizardButton("finish");
  189.         this._initWizardButton("cancel");
  190.         this._initWizardButton("extra1");
  191.         this._initWizardButton("extra2");
  192.         
  193.         this._initPages();
  194.         
  195.         window.addEventListener("close", this._closeHandler, false);
  196.         
  197.         // start off on the first page
  198.         this.pageCount = this.wizardPages.length;
  199.         this.advance();
  200.         
  201.         // give focus to the first focusable element in the dialog
  202.         window.addEventListener("load", this._setInitialFocus, false);
  203.       ]]></constructor>
  204.  
  205.       <method name="getPageById">
  206.         <parameter name="aPageId"/>
  207.         <body><![CDATA[
  208.           var els = this.getElementsByAttribute("pageid", aPageId);
  209.           return els.item(0);
  210.         ]]></body>
  211.       </method>
  212.       
  213.       <method name="extra1">
  214.         <body><![CDATA[
  215.           if (this.currentPage) 
  216.             this._fireEvent(this.currentPage, "extra1");
  217.         ]]></body>
  218.       </method>
  219.  
  220.       <method name="extra2">
  221.         <body><![CDATA[
  222.           if (this.currentPage) 
  223.             this._fireEvent(this.currentPage, "extra2");
  224.         ]]></body>
  225.       </method>
  226.  
  227.       <method name="rewind">
  228.         <body><![CDATA[
  229.           if (!this.canRewind)
  230.             return;
  231.  
  232.           if (this.currentPage && !this._fireEvent(this.currentPage, "pagehide"))
  233.             return;
  234.  
  235.           if (this.currentPage && !this._fireEvent(this.currentPage, "pagerewound"))
  236.             return;
  237.  
  238.           if (!this._fireEvent(this, "wizardback"))
  239.             return;
  240.             
  241.             
  242.           this._pageStack.pop();
  243.           this.currentPage = this._pageStack[this._pageStack.length-1];
  244.           this.setAttribute("pagestep", this._pageStack.length);
  245.         ]]></body>
  246.       </method>
  247.  
  248.       <method name="advance">
  249.         <parameter name="aPageId"/>
  250.         <body><![CDATA[
  251.           if (!this.canAdvance)
  252.             return; 
  253.             
  254.           if (this.currentPage && !this._fireEvent(this.currentPage, "pagehide"))
  255.             return;
  256.             
  257.           if (this.currentPage && !this._fireEvent(this.currentPage, "pageadvanced"))
  258.             return;
  259.  
  260.           if (this.onLastPage) {
  261.             if (this._fireEvent(this, "wizardfinish"))
  262.               window.setTimeout(function() {window.close();}, 1);
  263.           } else {
  264.             if (!this._fireEvent(this, "wizardnext"))
  265.               return; 
  266.             
  267.             var page;
  268.             if (aPageId)
  269.               page = this.getPageById(aPageId);
  270.             else {
  271.               if (this.currentPage) {
  272.                 if (this._accessMethod == "random")
  273.                   page = this.getPageById(this.currentPage.next);
  274.                 else
  275.                   page = this.wizardPages[this.currentPage.pageIndex+1];
  276.               } else
  277.                 page = this.wizardPages[0];
  278.             }
  279.  
  280.             if (page) {
  281.               this._pageStack.push(page);
  282.               this.setAttribute("pagestep", this._pageStack.length);
  283.   
  284.               this.currentPage = page;
  285.             }
  286.           }
  287.         ]]></body>
  288.       </method>
  289.       
  290.       <method name="goTo">
  291.         <parameter name="aPageId"/>
  292.         <body><![CDATA[
  293.           var page = this.getPageById(aPageId);
  294.           if (page) {
  295.             this._pageStack[this._pageStack.length-1] = page;
  296.             this.currentPage = page;
  297.           }
  298.         ]]></body>
  299.       </method>
  300.               
  301.       <method name="cancel">
  302.         <body><![CDATA[
  303.           if (!this._fireEvent(this, "wizardcancel"))
  304.             return true;
  305.  
  306.           window.close();
  307.           window.setTimeout(function() {window.close();}, 1);
  308.           return false;
  309.         ]]></body>
  310.       </method>
  311.       
  312.       <method name="_setInitialFocus">
  313.         <parameter name="aEvent"/>
  314.         <body>
  315.         <![CDATA[
  316.           document.documentElement._hasLoaded = true;
  317.           var focusInit = 
  318.             function() {
  319.               // give focus to the first focusable element in the dialog
  320.               if (!document.commandDispatcher.focusedElement)
  321.                 document.commandDispatcher.advanceFocusIntoSubtree(document.documentElement);
  322.             };
  323.  
  324.           // Give focus after onload completes, see bug 103197.
  325.           setTimeout(focusInit, 0);
  326.         ]]>
  327.         </body>
  328.       </method>                
  329.  
  330.       <method name="_advanceFocusToPage">
  331.         <parameter name="aPage"/>
  332.         <body>
  333.         <![CDATA[
  334.           if (!this._hasLoaded)
  335.             return;
  336.             
  337.           document.commandDispatcher.advanceFocusIntoSubtree(aPage);
  338.           
  339.           // if advanceFocusIntoSubtree tries to focus one of our
  340.           // dialog buttons, then remove it and put it on the root
  341.           var focused = document.commandDispatcher.focusedElement;
  342.           if (focused && focused.hasAttribute("dlgtype"))
  343.             this.focus();
  344.         ]]>
  345.         </body>
  346.       </method>                
  347.  
  348.       <method name="_initPages">
  349.         <body><![CDATA[
  350.           var meth = "sequential";
  351.           var pages = this.wizardPages;
  352.           for (var i = 0; i < pages.length; ++i) {
  353.             var page = pages[i];
  354.             page.pageIndex = i;
  355.             if (page.next != "")
  356.               meth = "random";
  357.           }
  358.           this._accessMethod = meth;
  359.         ]]></body>
  360.       </method>
  361.  
  362.       <method name="_initWizardButton">
  363.         <parameter name="aName"/>
  364.         <body><![CDATA[
  365.          var btn = document.getAnonymousElementByAttribute(this._wizardButtons, "dlgtype", aName);
  366.          if (btn) {
  367.            btn.addEventListener("command", this["_"+aName+"Func"], false);
  368.            this["_"+aName+"Button"] = btn;
  369.          }
  370.          return btn;
  371.         ]]></body>
  372.       </method>
  373.  
  374.       <method name="_adjustWizardHeader">
  375.         <body><![CDATA[
  376.           var label = this.currentPage.getAttribute("label");
  377.           if (!label && this.onFirstPage && this._bundle)
  378.             label = this._bundle.formatStringFromName("default-first-title", [this.title], 1);
  379.           else if (!label && this.onLastPage && this._bundle)
  380.             label = this._bundle.formatStringFromName("default-last-title", [this.title], 1);
  381.           this._wizardHeader.setAttribute("label", label);
  382.           this._wizardHeader.setAttribute("description", this.currentPage.getAttribute("description"));
  383.         ]]></body>
  384.       </method>
  385.  
  386.       <method name="_hitEnter">
  387.         <parameter name="evt"/>
  388.         <body>
  389.         <![CDATA[
  390.           if (!evt.getPreventDefault())
  391.             this.advance();
  392.         ]]>
  393.         </body>
  394.       </method>
  395.  
  396.       <method name="_fireEvent">
  397.         <parameter name="aTarget"/>
  398.         <parameter name="aType"/>
  399.         <body>
  400.         <![CDATA[
  401.           var event = document.createEvent("Events");
  402.           event.initEvent(aType, true, true);
  403.           
  404.           // handle dom event handlers
  405.           var noCancel = aTarget.dispatchEvent(event);
  406.           
  407.           // handle any xml attribute event handlers
  408.           var handler = aTarget.getAttribute("on"+aType);
  409.           if (handler != "") {
  410.             var fn = new Function("event", handler);
  411.             var returned = fn.apply(aTarget, [event]);
  412.             if (returned == false)
  413.               noCancel = false;
  414.           }
  415.  
  416.           return noCancel;
  417.         ]]>
  418.         </body>
  419.       </method>
  420.  
  421.     </implementation>
  422.  
  423.     <handlers>
  424.       <handler event="keypress" keycode="VK_ENTER"
  425.                group="system" action="this._hitEnter(event)"/>
  426.       <handler event="keypress" keycode="VK_RETURN"
  427.                group="system" action="this._hitEnter(event)"/>
  428.       <handler event="keypress" keycode="VK_ESCAPE" group="system">
  429.         if (!event.getPreventDefault())
  430.           this.cancel();
  431.       </handler>
  432.     </handlers>
  433.   </binding>
  434.  
  435.   <binding id="wizardpage" extends="chrome://global/content/bindings/wizard.xml#wizard-base">
  436.     <implementation>
  437.       <field name="pageIndex">-1</field>
  438.       
  439.       <property name="pageid" onget="return this.getAttribute('pageid');"
  440.                               onset="this.setAttribute('pageid', val);"/>
  441.  
  442.       <property name="next"   onget="return this.getAttribute('next');"
  443.                               onset="this.setAttribute('next', val);
  444.                                      this.parentNode._accessMethod = 'random';
  445.                                      return val;"/>
  446.     </implementation>
  447.   </binding>
  448.  
  449.  
  450.   <binding id="wizard-header" extends="chrome://global/content/bindings/wizard.xml#wizard-base">
  451.     <content>
  452.       <xul:hbox class="wizard-header-box-1" flex="1">
  453.         <xul:vbox class="wizard-header-box-text" flex="1">
  454.           <xul:label class="wizard-header-label" xbl:inherits="value=label"/>
  455.           <xul:label class="wizard-header-description" xbl:inherits="value=description"/>
  456.         </xul:vbox>
  457.         <xul:image class="wizard-header-icon" xbl:inherits="src=iconsrc"/>
  458.       </xul:hbox>
  459.     </content>
  460.   </binding>
  461.   
  462.   <binding id="wizard-buttons" extends="chrome://global/content/bindings/wizard.xml#wizard-base">
  463.     <content>
  464.       <xul:vbox class="wizard-buttons-box-1" flex="1">
  465.         <xul:separator class="wizard-buttons-separator groove"/>
  466.         <xul:hbox class="wizard-buttons-box-2">
  467.           <xul:button class="wizard-button" dlgtype="extra1" hidden="true"/>
  468.           <xul:button class="wizard-button" dlgtype="extra2" hidden="true"/>
  469.           <xul:spacer flex="1" anonid="spacer"/>
  470.           <xul:button label="&button-cancel-unix.label;" class="wizard-button"
  471.                       dlgtype="cancel" icon="cancel"/>
  472.           <xul:spacer style="width: 24px"/>
  473.           <xul:button label="&button-back-unix.label;" accesskey="&button-back-unix.accesskey;"
  474.                       class="wizard-button" dlgtype="back" icon="go-back"/>
  475.           <xul:deck class="wizard-next-deck" anonid="WizardButtonDeck">
  476.             <xul:hbox>
  477.               <xul:button label="&button-finish-unix.label;" class="wizard-button"
  478.                           dlgtype="finish" default="true" flex="1"/> 
  479.             </xul:hbox>
  480.             <xul:hbox>
  481.               <xul:button label="&button-next-unix.label;" accesskey="&button-next-unix.accesskey;"
  482.                           class="wizard-button" dlgtype="next" icon="go-forward" 
  483.                           default="true" flex="1"/> 
  484.             </xul:hbox>
  485.           </xul:deck>
  486.         </xul:hbox>
  487.       </xul:vbox>
  488.     </content>
  489.     
  490.     <implementation>
  491.       <field name="_wizardButtonDeck" readonly="true">
  492.         document.getAnonymousElementByAttribute(this, "anonid", "WizardButtonDeck");
  493.       </field>
  494.       
  495.       <method name="onPageChange">
  496.         <body><![CDATA[
  497.           if (this.getAttribute("lastpage") == "true") {
  498.             this._wizardButtonDeck.setAttribute("selectedIndex", 0);
  499.           } else {
  500.             this._wizardButtonDeck.setAttribute("selectedIndex", 1);
  501.           }
  502.         ]]></body>
  503.       </method>
  504.     </implementation>
  505.   </binding>
  506.  
  507. </bindings>
  508.